package com.cchc.k8s.config;

import java.io.Serializable;

/**
 * file：BaseResult.java
 * description:全局响应定义
 * date: 2021-09-18 09:22
 * author: wenrui
 * version: 1.0
 */
public class BaseResult<T> implements Serializable {
    private String code;
    private String msg;
    private T data;

    public BaseResult() {
    }

    public BaseResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static BaseResult create(String code, String msg) {
        return new BaseResult(code, msg);
    }

    public static BaseResult success() {
        return create(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg());
    }

    public static <T> BaseResult<T> success(T data) {
        return success().setData(data);
    }

    public static BaseResult fail() {
        return create(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMsg());
    }

    public static BaseResult fail(ResultCode resultCode) {
        return create(resultCode.getCode(), resultCode.getMsg());
    }

    public static BaseResult fail(String code, String msg) {
        return create(code, msg);
    }

    public BaseResult setData(T data) {
        this.data = data;
        return this;
    }

    public String getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(final String code) {
        this.code = code;
    }

    public void setMsg(final String msg) {
        this.msg = msg;
    }

    public String toString() {
        return "BaseResult(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }
}